#include "settingform.h"
#include "models/command.h"
#include "qtabbar.h"
#include "ui_settingform.h"

#include <models/curusermodel.h>

SettingForm::SettingForm(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::SettingForm)
    ,m_pButtonGroup(new QButtonGroup(this))
{
    ui->setupUi(this);
    ui->tabWidget->tabBar()->setVisible(false);
    ui->tabWidget->setDocumentMode(true);
    m_pButtonGroup->setExclusive(true);  // 设置互斥
    QFont f =ui->sys_setting_btn->font();
    f.setPixelSize(20*g_xScale);
    ui->sys_setting_btn->setFont(f);
    ui->user_manage_btn->setFont(f);
    ui->log_manage_btn->setFont(f);
    ui->video_manage_btn->setFont(f);
    m_pButtonGroup->addButton(ui->sys_setting_btn,SYS_SETTING);
    m_pButtonGroup->addButton(ui->user_manage_btn,USER_MANAGE);
    m_pButtonGroup->addButton(ui->log_manage_btn,LOG_MANAGE);
    m_pButtonGroup->addButton(ui->video_manage_btn,VIDEO_MANAGE);
    connect(m_pButtonGroup,SIGNAL(buttonToggled(int,bool)), this, SLOT(onSwitchSetPage(int,bool)));
}

SettingForm::~SettingForm()
{
    delete ui;
}

void SettingForm::onSwitchSetPage(int nID, bool b)
{
    if(b)
    {
        ui->tabWidget->setCurrentIndex(nID);
    }
}

void SettingForm::showEvent(QShowEvent *event)
{
    Q_UNUSED(event)
    if(CurUserModel::getInstance()->getUserName()!="admin")
    {
        ui->user_manage_btn->setVisible(false);
    }
    else
    {
        ui->user_manage_btn->setVisible(true);
    }
    ui->sys_setting_btn->setChecked(true);
}
